
<%@ page import="report.Activity" %>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <meta name="layout" content="main" />
        <title>iPET - Atividades</title>
    </head>
    <body>
        <g:render template="/common/menuActivity" />
        <div id="text">
        <div class="body">
            <g:if test="${flash.message}">
            <div class="message">${flash.message}</div>
            </g:if>
            <g:if test="${activitiesTotal != 0}">
            <div class="list">
                <h2>Atividades planejadas</h2>
                <table>
                    <thead>
                        <tr>
                            <th class="leftth actions">Ações</th>
                            <g:sortableColumn property="nature" title="${message(code: 'activity.nature.label', default: 'Natureza')}" />
                            <g:sortableColumn property="theme" title="${message(code: 'activity.theme.label', default: 'Tema')}" />
                            <g:sortableColumn class="rightth type" property="type" title="${message(code: 'activity.type.label', default: 'Tipo')}" />
                        </tr>
                    </thead>
                    <tbody>
                    <g:each in="${activitiesPlannedList}" status="i" var="activityInstance">
                        <tr class="${(i % 2) == 0 ? 'odd' : 'even'} ${i == 0 ? 'first' : ''}">
                            <td>
                            	<g:if test="${activityInstance.isLate(today)}"><img alt="Late" title="Atrasada" src="${resource(dir:'images/icons',file:'exclamation.png')}" /></g:if>
                            	<div class="actions">
						            <g:link action="show" controller="activity" id="${activityInstance.id}" title="Visualizar"><img alt="Edit" src="${resource(dir:'images/icons',file:'view.png')}" /></g:link>
						            <g:if test="${session.user.isAdmin || activityInstance.sponsors.contains(session.user)}">
							            <g:link action="edit" controller="activity" id="${activityInstance.id}" title="Editar"><img alt="Edit" src="${resource(dir:'images/icons',file:'edit.png')}" /></g:link>
							            <g:link action="delete" controller="activity" id="${activityInstance.id}" title="Excluir" onclick="if (confirm('Esta ação não pode ser desfeita, tem certeza?')) { var f = document.createElement('form'); f.style.display = 'none'; this.parentNode.appendChild(f); f.method = 'POST'; f.action = this.href; f.submit(); };return false;"><img alt="Delete" src="${resource(dir:'images/icons',file:'trash.png')}" /></g:link>
						            </g:if>
								</div>
                            </td>
                            <td>${fieldValue(bean: activityInstance, field: "nature")}</td>
                            <td>${fieldValue(bean: activityInstance, field: "theme")}</td>
                            <td>${fieldValue(bean: activityInstance, field: "type")}</td>
                        </tr>
                    </g:each>
                    </tbody>
                </table>
                <br />
                <h2>Atividades em andamento</h2>
                <table>
                    <thead>
                        <tr>
                            <th class="leftth actions">Ações</th>
                            <g:sortableColumn property="nature" title="${message(code: 'activity.nature.label', default: 'Natureza')}" />
                            <g:sortableColumn property="theme" title="${message(code: 'activity.theme.label', default: 'Tema')}" />
                            <g:sortableColumn class="rightth type" property="type" title="${message(code: 'activity.type.label', default: 'Tipo')}" />
                        </tr>
                    </thead>
                    <tbody>
                    <g:each in="${activitiesOngoingList}" status="i" var="activityInstance">
                        <tr class="${(i % 2) == 0 ? 'odd' : 'even'} ${i == 0 ? 'first' : ''}">
                            <td>
                            	<div class="actions">
						            <g:link action="show" controller="activity" id="${activityInstance.id}" title="Visualizar"><img alt="Edit" src="${resource(dir:'images/icons',file:'view.png')}" /></g:link>
						            <g:if test="${session.user.isAdmin || activityInstance.sponsors.contains(session.user)}">
							            <g:link action="edit" controller="activity" id="${activityInstance.id}" title="Editar"><img alt="Edit" src="${resource(dir:'images/icons',file:'edit.png')}" /></g:link>
							            <g:link action="delete" controller="activity" id="${activityInstance.id}" title="Excluir" onclick="if (confirm('Esta ação não pode ser desfeita, tem certeza?')) { var f = document.createElement('form'); f.style.display = 'none'; this.parentNode.appendChild(f); f.method = 'POST'; f.action = this.href; f.submit(); };return false;"><img alt="Delete" src="${resource(dir:'images/icons',file:'trash.png')}" /></g:link>
							            <g:link action="confirm" controller="activity" id="${activityInstance.id}" title="Concluir" onclick="var f = document.createElement('form'); f.style.display = 'none'; this.parentNode.appendChild(f); f.method = 'POST'; f.action = this.href; f.submit();return false;"><img alt="Edit" src="${resource(dir:'images/icons',file:'confirm.png')}" /></g:link>
						            </g:if>
								</div>
                            </td>
                            <td>${fieldValue(bean: activityInstance, field: "nature")}</td>
                            <td>${fieldValue(bean: activityInstance, field: "theme")}</td>
                            <td>${fieldValue(bean: activityInstance, field: "type")}</td>
                            <g:if test="${activityInstance.isLate(today)}"><td><img alt="Late" title="Atrasada" src="${resource(dir:'images/icons',file:'exclamation.png')}" /></td></g:if>
                        </tr>
                    </g:each>
                    </tbody>
                </table>
                <br/>
                <h2>Atividades concluídas</h2>
                <table>
                    <thead>
                        <tr>
                            <th class="leftth actions">Ações</th>
                            <g:sortableColumn property="nature" title="${message(code: 'activity.nature.label', default: 'Natureza')}" />
                            <g:sortableColumn property="theme" title="${message(code: 'activity.theme.label', default: 'Tema')}" />
                            <g:sortableColumn class="rightth type" property="type" title="${message(code: 'activity.type.label', default: 'Tipo')}" />
                        </tr>
                    </thead>
                    <tbody>
                    <g:each in="${activitiesFinishedList}" status="i" var="activityInstance">
                        <tr class="${(i % 2) == 0 ? 'odd' : 'even'} ${i == 0 ? 'first' : ''}">
                            <td>
								<div class="actions">
            						<g:link action="show" controller="activity" id="${activityInstance.id}" title="Visualizar"><img alt="Edit" src="${resource(dir:'images/icons',file:'view.png')}" /></g:link>
						            <g:if test="${session.user.isAdmin || activityInstance.sponsors.contains(session.user)}">
							            <g:link action="edit" controller="activity" id="${activityInstance.id}" title="Editar"><img alt="Edit" src="${resource(dir:'images/icons',file:'edit.png')}" /></g:link>
							            <g:link action="delete" controller="activity" id="${activityInstance.id}" title="Excluir" onclick="if (confirm('Esta ação não pode ser desfeita, tem certeza?')) { var f = document.createElement('form'); f.style.display = 'none'; this.parentNode.appendChild(f); f.method = 'POST'; f.action = this.href; f.submit(); };return false;"><img alt="Delete" src="${resource(dir:'images/icons',file:'trash.png')}" /></g:link>
						            </g:if>
								</div>
				 	         </td>
                            <td>${fieldValue(bean: activityInstance, field: "nature")}</td>
                            <td>${fieldValue(bean: activityInstance, field: "theme")}</td>
                            <td>${fieldValue(bean: activityInstance, field: "type")}</td>
                        </tr>
                    </g:each>
                    </tbody>
                </table>
            </div>
            </g:if>
            <g:else>
            	<h2>Atividades de ${year}</h2>
            	<div class="dialog createBlank">
					<h1><g:link action="create" controller="activity">Cadastre a primeira atividade</g:link></h1>
					<p>Quando cadastrado uma atividade, será listado um resumo de informações sobre a mesma.</p>
				</div>
            </g:else>
        </div>
        </div>
    </body>
</html>
